<template>
  <!-- fqc及oqc检验单界面 -->
  <div>
    <basic-container>
      <avue-crud
        :option="option"
        :table-loading="loading"
        :search.sync="query"
        :data="data"
        :page.sync="page"
        :before-open="beforeOpen"
        v-model="form"
        ref="crud"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        :key="timer"
        @on-load="onLoad"
      >
        <template slot="menuRight">
          <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
        </template>
        <template slot="menuLeft">
          <div style="display: flex">
            <el-button v-if="showBtn" type="primary" size="small" :disabled="ids.length > 0 ? false : true" @click="recheck">发起重检</el-button>
            <el-button
              type="primary"
              size="small"
              :disabled="ids.length > 0 ? false : true"
              @click="cancel"
              v-if="$route.path === '/quality/checkLists/1' && permission.fqcCheck_cancel"
              >撤 销</el-button
            >
          </div>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" v-if="permission.fqcCheckList_view" icon="el-icon-view" size="small" @click.stop="handleView(scope.row)"
            >查看
            <!-- v-if=" scope.row.category === 1" -->
          </el-button>
        </template>
      </avue-crud>
      <el-dialog ref="dialog" title="查看" append-to-body :visible.sync="showDialog" v-if="showDialog" :close-on-click-modal="dialogClose">
        <el-tabs type="card" v-if="showDialog" @tab-click="handleTabClick($event)" v-model="tabsIndex">
          <el-tab-pane label="检验项详情" name="1">
            <avue-form ref="aplProperties" v-model="viewModel" :option="viewOption">
              <template slot="info" v-if="viewModel.attributeResultVOList && viewModel.attributeResultVOList.length > 0">
                <avue-form
                  ref="itemProperties"
                  v-for="(item, index) in viewModel.attributeResultVOList || []"
                  v-model="viewModel.attributeResultVOList[index]"
                  :option="itemOption"
                  :key="index"
                >
                  <template slot="info2">
                    <span style="display: block">检验项： {{ item.item ? item.item.itemName : '' }}</span>
                    <span style="display: block">检验明细项：{{ item.itemAttributeName }}</span>
                    <span style="display: block">检验标准：{{ item.testCriterion }}</span>
                    <span style="display: block">检验工具：{{ item.testTool }}</span>
                    <div v-if="item.examineRealValue.type === 'SELECT'">
                      <div style="display: flex; flex-direction: row" v-for="(selectItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ selectItem.label }}：</label>
                        <div style="width: 200px; margin-top: 5px">
                          <el-select disabled v-model="selectItem.selectValue">
                            <el-option v-for="item3 in selectItem.selectList" :key="item3.dictKey" :label="item3.dictValue" :value="item3.dictKey"> </el-option>
                          </el-select>
                        </div>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'SINGLE-INPUT'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label }}：</label>
                        <el-input style="width: 200px; margin-bottom: 5px" :value="scanItem.value" :disabled="true"> </el-input>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'MULTIPLE-INPUT'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2" style="margin-bottom: 5px">
                        <label>{{ scanItem.label }}：</label>
                        <table border="1">
                          <tr>
                            <th width="50" style="text-align: center">次数</th>
                            <th width="70" style="text-align: center">测试值</th>
                            <th width="120" style="text-align: center">测试结果</th>
                            <th width="70" style="text-align: center">操作</th>
                          </tr>
                          <tr v-for="(result, index3) in item.examineRealValue.options[index2].valueResults" :key="index3">
                            <td style="text-align: center">{{ result.sequence }}</td>
                            <td style="text-align: center">{{ result.value }}</td>
                            <td style="text-align: center">
                              <span>{{ result.result }}</span>
                              <!-- <span style="margin-right: 2px"><input checked type="radio"/>OK</span> <span><input type="radio"/>NG</span> -->
                            </td>
                            <td style="text-align: center; color: red"><div>x</div></td>
                          </tr>
                        </table>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'RADIO'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label }}：</label>
                        <el-radio v-model="scanItem.valueResults" disabled :label="scanItem.realLabel">{{ scanItem.realLabel }}</el-radio>
                        <el-radio v-model="scanItem.valueResults" disabled :label="scanItem.shamLabel">{{ scanItem.shamLabel }}</el-radio>
                      </div>
                    </div>
                    <div v-if="item.examineRealValue.type === 'SCAN'">
                      <div v-for="(scanItem, index2) in item.examineRealValue.options" :key="index2">
                        <label>{{ scanItem.label + '数量' }}：</label>
                        <el-input style="width: 200px" :value="item.examineRealValue.scanContent.length" :disabled="true"> </el-input>
                      </div>
                    </div>
                    <div>
                      <label>不良登记：</label>
                      <table border="1">
                        <tr>
                          <th width="120" style="text-align: center">严重程度</th>
                          <th width="70" style="text-align: center">不良数量</th>
                          <th width="70" style="text-align: center">条码类型</th>
                          <th width="400" style="text-align: center">不良条码</th>
                        </tr>
                        <tr>
                          <td style="text-align: center">严重问题（CRI）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].criQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].criList.length > 0 && viewModel.attributeResultVOList[index].criList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].criList | defectfilter }}</td>
                        </tr>
                        <tr>
                          <td style="text-align: center">主要问题（MAJ）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].majQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].majList.length > 0 && viewModel.attributeResultVOList[index].majList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].majList | defectfilter }}</td>
                        </tr>
                        <tr>
                          <td style="text-align: center">次要问题（MIN）</td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].minQuantity || '' }}</td>
                          <td style="text-align: center">
                            {{ viewModel.attributeResultVOList[index].minList.length > 0 && viewModel.attributeResultVOList[index].minList[0].objectType | packTypefilter }}
                          </td>
                          <td style="text-align: center">{{ viewModel.attributeResultVOList[index].minList | defectfilter }}</td>
                        </tr>
                      </table>
                    </div>
                  </template>
                </avue-form>
              </template>
              <template slot="info" v-else>
                <span></span>
              </template>
              <template slot="attachments">
                <div>
                  <div style="display: inline-block; text-align: center" v-for="(item, index) in viewModel.attachments" :key="item.attachmentId">
                    <img style="width: 100px; height: 100px; padding-right: 10px; display: block" :src="item.link" @click="openPreview(index, item.link)" />
                    <!-- <el-button type="text" v-if="item.link" icon="el-icon-download" size="small" @click="handleDownload(item)">下载 </el-button> -->
                  </div>
                </div>
              </template>
            </avue-form>
          </el-tab-pane>
          <el-tab-pane label="条码记录" name="2">
            <avue-form v-model="detailData" :option="detailOption"></avue-form>
          </el-tab-pane>
          <el-tab-pane label="AQL" name="3">
            <div v-for="(item, index) in inspectionAqlList" :key="index">
              <avue-form v-model="inspectionAqlList[index]" :option="aqlOption"> </avue-form>
            </div>
          </el-tab-pane>
        </el-tabs>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
        </span>
      </el-dialog>
      <!-- <el-dialog
        ref="dialog"
        title="查看详情"
        append-to-body
        :visible.sync="showDialog"
        v-if="showDialog && selectRouteObj.documentType === 'FQC'"
        :close-on-click-modal="dialogClose"
      >
        <avue-form v-model="detailData" :option="detailOption"></avue-form>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
        </span>
      </el-dialog> -->
    </basic-container>
  </div>
</template>

<script>
import { getPage, getDetail, repeatExam, cancel, getQcCalculateAqlInfo } from '@/api/quality/checkLists.js';

import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';

export default {
  components: {
    userTableConfig
  },
  mixins: [userConfig()],
  inject: ['reload'],
  filters: {
    packTypefilter(type) {
      switch (type) {
        case 'PACKING':
          return '包装条码';
        case 'PRODUCT':
          return '产品';
        case 'CARRIER':
          return '载具';
        default:
          break;
      }
    },
    defectfilter(data) {
      let arr = data || [];
      let objectSns = arr.map((item) => {
        return item.objectSn;
      });
      return String(objectSns);
    }
  },
  data() {
    return {
      pageCode: 'CHECKLIST',
      form: {
        deptId: '',
        lineId: ''
      },
      search: {},
      query: {},
      loading: true,
      isLock: true,
      tabsIndex: '1',
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      aqlModel: {
        attributeResultVOList: []
      },
      inspection: {},
      viewModel: {},
      inspectionAqlList: [],
      aqlOption: {
        emptyBtn: false,
        submitBtn: false,
        column: [
          {
            label: '抽样标准',
            prop: 'samplingStandard',
            type: 'select',
            span: 8,
            labelWidth: 160,
            row: true,
            disabled: true,
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            control: (val, form) => {
              if (val === 'MIL-STD-1916 C-0') {
                return {
                  severityCode: {
                    display: false
                  },
                  levelType: {
                    display: false
                  },
                  levelCode: {
                    display: false
                  }
                };
              } else {
                return {
                  severityCode: {
                    display: true
                  },
                  levelType: {
                    display: true
                  },
                  levelCode: {
                    display: true
                  }
                };
              }
            }
          },
          {
            label: '严重程度',
            prop: 'severityCode',
            span: 8,
            labelWidth: 160,
            type: 'select',
            row: true,
            disabled: true,
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_plan',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验水平',
            prop: 'levelType',
            span: 8,
            row: true,
            labelWidth: 160,
            disabled: true,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=aql_inspection_level',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验水平代码',
            prop: 'levelCode',
            span: 8,
            row: true,
            labelWidth: 160,
            disabled: true
          },
          {
            label: '质量水平代码',
            prop: 'limitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'sampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'acceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'rejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '严重缺陷抽样水平代码',
            prop: 'severityLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'severitySampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'severityAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'severityRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '主要缺陷抽样水平代码',
            prop: 'majorLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'majorSampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'minorAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'majorRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: '次要缺陷抽样水平代码',
            prop: 'minorLimitCode',
            labelWidth: 160,
            span: 8,
            disabled: true
          },
          {
            label: '抽检数量',
            prop: 'minorSampleQuantity',
            span: 6,
            labelWidth: 80,
            disabled: true
          },
          {
            label: 'Ac',
            prop: 'minorAcceptQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          },
          {
            label: 'Re',
            prop: 'minorRejectQuantity',
            span: 4,
            labelWidth: 40,
            disabled: true
          }
        ]
      },
      viewOption: {
        emptyBtn: false,
        submitBtn: false,
        labelWidth: '160',
        column: [
          {
            labelWidth: 60,
            label: '',
            prop: 'info',
            span: 24,
            hide: true,
            row: true,
            formslot: true
          },
          // {
          //   label: '检验结果',
          //   prop: 'examineResult',
          //   type: 'radio',
          //   span: 24,
          //   disabled: true,
          //   labelWidth: 100,
          //   row: true,
          //   dicData: [
          //     {
          //       label: 'OK',
          //       value: 'OK'
          //     },
          //     {
          //       label: 'NG',
          //       value: 'NG'
          //     }
          //   ]
          // },
          {
            label: '综合判定结果',
            prop: 'examineResult',
            type: 'radio',
            span: 24,
            disabled: true,
            labelWidth: 100,
            row: true,
            dicData: [
              {
                label: 'OK',
                value: 'OK'
              },
              {
                label: 'NG',
                value: 'NG'
              }
            ]
          },
          {
            label: '附件',
            prop: 'attachments',
            span: 24,
            formslot: true,
            disabled: true
          },
          {
            label: '备注/原因',
            prop: 'remark',
            span: 20,
            type: 'textarea',
            maxRows: 3,
            minRows: 3,
            disabled: true,
            row: true
          }
        ]
      },
      itemOption: {
        emptyBtn: false,
        submitBtn: false,
        labelWidth: '160',
        column: [
          {
            labelWidth: 60,
            label: '',
            prop: 'info2',
            span: 24,
            hide: true
          },
          {
            label: '检验结果',
            prop: 'examineResult',
            type: 'radio',
            span: 24,
            disabled: true,
            labelWidth: 100,
            row: true,
            formslot: true,
            dicData: [
              {
                label: 'OK',
                value: 'OK'
              },
              {
                label: 'NG',
                value: 'NG'
              }
            ]
          }
        ]
      },
      option: {
        height: 'calc(100vh - 485px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 24,
        searchMenuPosition: 'right',
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        dialogClickModal: false,
        labelWidth: 120,
        searchSpan: 6,
        addBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        // 查看
        viewBtn: false,
        menuWidth: 100,
        columnBtn: false,
        column: [
          {
            label: '检验单号',
            prop: 'documentNo',
            search: true,
            minWidth: 150,
            searchOrder: 1
          },
          {
            label: '工单号',
            minWidth: 150,
            search: true,
            searchOrder: 2,
            prop: 'sourceNo'
          },
          {
            label: '检验状态',
            prop: 'status',
            type: 'select',
            search: true,
            searchOrder: 5,
            dicData: [
              {
                label: '未检验',
                value: 1
              },
              {
                label: '已检验',
                value: 2
              }
            ]
          },
          {
            label: '检验时机',
            prop: 'triggerPoint',
            type: 'select',
            dicData: [
              {
                label: '发货前',
                value: 'OQC_BEFORE_DELIVERY'
              },
              {
                label: '入库前',
                value: 'OQC_BEFORE_INBOUND'
              },
              {
                label: '发货前',
                value: 'FQC_BEFORE_DELIVERY'
              },
              {
                label: '入库前',
                value: 'FQC_BEFORE_INBOUND'
              },
              {
                label: '包装前',
                value: 'FQC_BEFORE_PACKING'
              }
            ]
          },
          // {
          //     label: '发货单号',
          //     minWidth: 120,
          //     search: true,
          //     searchOrder: 2,
          //     prop: 'sheetNo'
          // },
          {
            label: '产品编码',
            prop: 'partNo',
            minWidth: 100,
            search: true,
            searchOrder: 3
          },
          {
            label: '产品名称',
            minWidth: 100,
            prop: 'partName'
          },
          {
            label: '产品规格',
            minWidth: 100,
            prop: 'partModel'
          },
          {
            label: '报检数量',
            prop: 'sendExamineQuantity'
          },
          {
            label: '特许合格',
            prop: 'extractionQuantity'
          },

          {
            label: '检验结果',
            prop: 'examineResult',
            type: 'select',
            search: true,
            searchOrder: 6,
            // dicFlag: false,
            dicUrl: '/api/blade-system/dict/dictionary?code=examineResult',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '报检日期',
            minWidth: 150,
            prop: 'sendExamineDate',
            type: 'datetime',
            search: true,
            searchOrder: 4,
            searchType: 'daterange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期'
          },
          // {
          //     label: '事务时间',
          //     prop: 'transactionTime',
          //     search: true,
          //     searchOrder: 7,
          //     searchSpan: 8,
          //     searchType: 'datetimerange',
          //     format: 'yyyy-MM-dd HH:mm:ss',
          //     valueFormat: 'yyyy-MM-dd HH:mm:ss',
          //     startPlaceholder: '开始日期',
          //     endPlaceholder: '结束日期'
          // },
          {
            label: '报检人员',
            prop: 'sendExamineByName'
          },
          {
            label: '抽检条码',
            prop: 'objectSns',
            hide: true,
            search: true
          }
        ]
      },
      data: [],
      dialogVisible: false,
      dialogForm: {
        isQualified: null
      },
      // 车间列表
      workshopList: [],
      repairSuccessVisible: false,
      repairSuccessForm: {
        scrapReason: ''
      },
      rulesSuccessForm: {
        scrapReason: [{ required: true, message: '请输入报废原因', trigger: 'blur' }]
      },
      // 判断是在那个routeName下的
      selectRouteObj: {
        documentType: ''
      },
      timer: new Date().getTime(),
      showDialog: false,
      detailData: {},
      detailOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '130',
        column: [
          {
            label: '检验条码',
            prop: 'objectSn',
            type: 'textarea',
            rows: 5,
            span: 24,
            disabled: true,
            placeholder: '检验条码'
          },
          {
            label: '不良条码',
            prop: 'NGSn',
            type: 'textarea',
            rows: 5,
            span: 24,
            disabled: true,
            placeholder: '不良条码'
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(['permission']),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    },
    showBtn() {
      if (this.$route.path === '/quality/checkLists/1') {
        return this.permission.fqcCheckList_recheck;
      } else {
        return this.permission.oqcCheckList_recheck;
      }
    }
  },
  // beforeRouteEnter(to, from, next) {
  //   next((vm) => {
  //     vm.page = {
  //       pageSize: 20,
  //       currentPage: 1,
  //       total: 0
  //     };

  //     // 通过 `vm` 访问组件实例
  //     vm.init();
  //     vm.searchReset();
  //   });
  // },
  watch: {
    async $route() {
      let whiteList = ['/quality/checkLists/1', '/quality/checkLists/2'];
      if (whiteList.includes(this.$route.path)) {
        this.isLock = false;
        this.init();
        this.newKey();
        this.page = {
          pageSize: 20,
          currentPage: 1,
          total: 0
        };
        this.query = {};
        await this.onLoad(this.page);
        this.$nextTick(() => {
          this.$structuralSplit();
        });
      }
    }
  },
  mounted() {
    if (this.isLock) {
      this.onLoad(this.page);
      this.$nextTick(() => {
        this.$structuralSplit();
      });
    }
  },
  methods: {
    init() {
      let extractionColumn = this.findObject(this.option.column, 'extractionQuantity');
      if (this.$route.path === '/quality/checkLists/1') {
        this.option.column[1].label = '工单号';
        this.selectRouteObj.documentType = 'FQC';
        extractionColumn.hide = true;
        // this.refreshChange()
      } else if (this.$route.path === '/quality/checkLists/2') {
        this.option.column[1].label = '单据号';
        extractionColumn.hide = false;
        this.selectRouteObj.documentType = 'OQC';
        // this.refreshChange()
      }
    },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (params.sendExamineDate && params.sendExamineDate.length > 0) {
        params.startSendExamineDate = params.sendExamineDate[0];
        params.endSendExamineDate = params.sendExamineDate[1];
        delete params.sendExamineDate;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      let objectSnsColumn = this.findObject(this.option.column, 'objectSns');
      console.log(objectSnsColumn, 22222222);
      if (this.$route.path === '/quality/checkLists/1') {
        this.option.column[1].label = '工单号';
        this.selectRouteObj.documentType = 'FQC';
        this.option.searchMenuSpan = 24;
        objectSnsColumn.search = true;
      } else if (this.$route.path === '/quality/checkLists/2') {
        this.option.column[1].label = '单据号';
        this.selectRouteObj.documentType = 'OQC';
        objectSnsColumn.search = false;
        this.option.searchMenuSpan = 12;
      }
      this.loading = true;
      this.query.documentType = this.selectRouteObj.documentType;
      this.query.descs = 'send_examine_date';
      getPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    openPreview(index = 0, link) {
      this.$ImagePreview([{ url: link }], index, {
        closeOnClickModal: false
      });
    },
    recheck() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        if (ele.status === 2) {
          ids.push(ele.id);
        }
      });
      if (ids.length < 1) {
        this.$message({
          type: 'warning',
          message: '请确保选择的数据是已检验的！'
        });
        return;
      }
      this.$confirm('确定将选择数据重检?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return repeatExam(ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    cancel() {
      this.$confirm('确定将选择的检验单撤销报检？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return cancel({
            ids: String(this.ids),
            documentType: 'FQC'
          });
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    newKey() {
      this.timer = new Date().getTime();
    },
    handleView(row) {
      this.inspection.rowData = row;
      this.tabsIndex = '1';
      getDetail(row.id).then((res) => {
        let data = res.data.data;
        this.viewModel = data;
        //AQL
        this.inspectionAqlList = data.inspectionAqlList || [];
        //检验项数据
        this._forEach(this.viewModel.attributeResultVOList || [], (item) => {
          if (!item.criList) {
            item.criList = [];
          }
          if (!item.majList) {
            item.majList = [];
          }
          if (!item.minList) {
            item.minList = [];
          }
          item.examineRealValue = JSON.parse(item.examineRealValue);
        });
        console.log(this.viewModel.attributeResultVOList, 4444);
        //条码记录
        let objectSn = [];
        let NGSn = [];
        this._forEach(data.inspectionObjectList, (item) => {
          objectSn.push(item.objectSn);
          if (item.isNg) {
            NGSn.push(item.objectSn);
          }
        });
        this.detailData.objectSn = objectSn.join('、');
        this.detailData.NGSn = NGSn.join('、');
      });

      this.showDialog = true;
    },
    async handleTabClick({ index }) {}
  }
};
</script>

<style></style>
